/*
 * Copyright(c) 2018-? the original author[Wien(luweien@aliyun.com)] or authors.
 *
 */
package org.doll.it.web.session;

import java.time.Duration;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.session.data.mongo.JdkMongoSessionConverter;
import org.springframework.session.data.mongo.config.annotation.web.http.EnableMongoHttpSession;
import org.springframework.session.web.http.HeaderHttpSessionIdResolver;
import org.springframework.session.web.http.HttpSessionIdResolver;

@Configuration
@EnableMongoHttpSession
public class DollSessionConfig {

	@Bean
	public JdkMongoSessionConverter jdkMongoSessionConverter() {
		// Session默认时间30分钟
		return new JdkMongoSessionConverter(Duration.ofMinutes(30));
	}

	// API
	@Bean
	public HttpSessionIdResolver httpSessionIdResolver() {
		return HeaderHttpSessionIdResolver.xAuthToken();
	}

	// Cookie
	//	@Bean
	//	public CookieSerializer cookieSerializer() {
	//		DefaultCookieSerializer serializer = new DefaultCookieSerializer();
	//		serializer.setCookieName("JSESSIONID");
	//		serializer.setCookiePath("/");
	//		serializer.setDomainNamePattern("^.+?\\.(\\w+\\.[a-z]+)$");
	//		return serializer;
	//	}
}